{{template "/admin/common/ly_header.html" .}}

<style>
    .home {
        display: flex;
    }

    .home_sidebar {
        width: 250px;
        height: calc(100vh - 68px);
        background-color: #ffffff;
    }

    .home_container {
        flex: 1;
        padding: 20px;
    }
</style>
<div class="home">
    <div class="home_sidebar">
        <!--        侧边栏-->
        {{template "/admin/common/ly_sidebar.html" .}}
    </div>
    <div class="home_container">
        <h1>写文章</h1>
        <div class="uk-grid ">
            <div class="uk-width-2-3@m">
                <input class="uk-input " type="text" name="username" placeholder="文章标题" id="title">
                <div id="div1" style="margin-top: 10px">
                </div>
            </div>
            <div class="uk-width-1-3@m ">

                <div class="uk-form-stacked" style="text-align: left">
                    <label class="uk-form-label" for="form-stacked-text">选择分类</label>
                    <div class="uk-form-controls">
                        <select class="uk-select sort" id="form-stacked-text">
                            {{range $index,$elem:= .Sort}}
                            <option value="{{$elem.id}}">{{$elem.title}}</option>
                            {{end}}
                        </select>
                    </div>
                </div>
                <div class="uk-form-stacked" style="text-align: left">
                    <label class="uk-form-label" for="form-stacked-tag">选择标签</label>
                    <div class="uk-form-controls">
                        <input class="uk-input " id="form-stacked-tag" type="text" name="username" placeholder="标签">
                    </div>
                </div>
                <div class="uk-form-stacked" style="text-align: left">
                    <button class="uk-button uk-button-primary uk-width-1-1 uk-margin-small-bottom"
                            style="margin-top: 10px" id="btn">发布文章
                    </button>
                </div>
            </div>
        </div>

        <script
                type="text/javascript"
                src="/static/js/admin/wangEditor.min.js"
        ></script>
        <script type="text/javascript">
            const E = window.wangEditor
            const editor = new E("#div1")
            // 或者 const editor = new E(document.getElementById('div1'))
            editor.create()

            var btn = document.querySelector('#btn')
            btn.addEventListener('click', function () {
                // 组装数据
                var data = {
                    title: $('#title').val(),
                    html: editor.txt.html(),
                    text: editor.txt.text(),
                    sort: $('.sort').val(),
                }
                // 发生post请求
                $.ajax({
                    type: "POST",
                    url: "/admin/addWrite",
                    data: data,
                    dataType: "json",
                    success: function (data) {
                        console.log(data, 'data',data.code)
                        window.location.href = "/admin/admin"
                    }
                });
            })
        </script>
    </div>
</div>
{{template "/admin/common/ly_footer.html" .}}